package com.heima.comment.controller;


import com.heima.comment.pojo.Comment;
import com.heima.comment.service.CommentService;
import com.heima.comment.dtos.CommentDto;
import com.heima.comment.dtos.CommentLikeDto;
import com.heima.comment.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/v1/comment")
@RequiredArgsConstructor
public class CommentController {

    private final CommentService commentService;

    /**
     * 保存评论
     *
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentSaveDto dto) {
        log.info("保存评论执行啦，网关没有问题");
        commentService.saveComment(dto);
        return ResponseResult.okResult(null);
    }


    @PostMapping("/load")
    public ResponseResult load(@RequestBody CommentDto dto) {
        log.info("查询评论列表行啦，网关没有问题");
        List<Comment> comments = commentService.loadComment(dto);
        return ResponseResult.okResult(comments);
    }

    @PostMapping("/like")
    public ResponseResult like(CommentLikeDto likeDto){
        commentService.like(likeDto);
        return ResponseResult.okResult(null);
    }

}
